package com.llt.chatroom.controller;

import com.llt.chatroom.model.Message;
import com.llt.chatroom.service.MessageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {

    @Resource
    MessageService messageService;

    @GetMapping("/message")
    public Object getMessage(int sessionId) {

        List<Message> messages = messageService.getMessagesBySessionId(sessionId);
        // 查询出的为按照时间降序，需要按照时间升序
        Collections.reverse(messages);

        return messages;
    }
}
